class Solution:
    def longestPalindrome(self, s: str) -> str:
        if not s: return ""
        lens = len(s)
        if lens == 0 or s == s[::-1]: return s
        start,maxLen = 0 , 1
        for i in range(1,lens):
            neighbor =s[i-maxLen:i+1]
            sides = s[i-maxLen-1:i+1]
            if i-maxLen >=0 and neighbor==neighbor[::-1]:
                start = i-maxLen
                maxLen += 1
            if i-maxLen-1 >=0 and sides==sides[::-1]:
                start = i-maxLen-1
                maxLen += 2
        return s[start:start+maxLen]

class Solution:
    def longestPalindrome(self, s: str) -> str:
        if not s: return ""
        length  = len(s)
        if length == 1 or s == s[::-1]: return s
        start, maxLen = 0,1
        for i in range(1,length):
            neighbor = s[i-maxLen:i+1]
            sides = s[i-maxLen-1:i+1]
            if i-maxLen >=0 and neighbor == neighbor[::-1]:
                start= i - maxLen
                maxLen += 1
            if i-maxLen-1 >=0 and sides == sides[::-1]:
                start= i - maxLen -1
                maxLen += 2
        return s[start:start+maxLen]
'''
>=0 0是第一位！
末尾是i+1，因为回文啊哟判断start和maxLEn
能判断的最大程度是lens-1或者lens-2
增加的逻辑走的是sides的逻辑，增加需要maxLen+1
初始有坑呢相邻走的时候neighbor的逻辑
'''
class Solution:
    def longestPalindrome(self, s: str) -> str:
        for lens in range(len(s),-1,-1):
            for start in range(0,len(s)-lens+1):
                if s[start:start+lens] == s[start:start+lens][::-1]:
                    return s[start:start+lens]